<?php

namespace app\index\controller;

use craw\craw;
use think\Controller;
use think\Request;
use think\View;

class Index extends Controller
{
    protected $c;

    public function __construct(Request $request = null)
    {
        parent::__construct();
        $this->c = new craw();
    }

    public function index()
    {
        $movies = $this->c->getList(2, 12)['data'];
        $tvs = $this->c->getList(1, 12)['data'];
        $zys = $this->c->getList(3, 12)['data'];
        $dms = $this->c->getList(4, 12)['data'];
        $yhq = $this->c->getyhqList(1, 12, null, null, true);

        return $this->fetch('index', ['movies' => $movies, 'tvs' => $tvs, 'zys' => $zys, 'dms' => $dms, 'yhq' => $yhq['data']]);
    }

    public function search()
    {
        return 1;
    }

    public function movies()
    {
        $cat = input('cat');
        $page = empty(input('p')) ? 1 : input('p');
        $items = $this->c->getList('2', 30, $page, $cat);

        $this->assign('cat', $cat);
        $this->assign('list', $items['data']);
        $this->assign('pagecount', $items['pagecount']);
        $this->assign('page', $page);
        return $this->fetch();
    }

    public function play()
    {
        $url = base64_decode(urldecode(input('id')));
        $movie = $this->c->getMovie($url);
        var_dump( $movie);
    }

    public function yhq()
    {
        $cid = empty(input('c')) ? 0 : input('c');
        $page = empty(input('p')) ? 1 : input('p');

        $items = $this->c->getyhqList(1, -1, $page, $cid, true);

        $this->assign('list', $items['data']);
        $this->assign('cid', $cid);
        $this->assign('page', $page);
        $this->assign('pagecount', $items['pagecount']);

        return $this->fetch();
    }

    public function redir()
    {
        $url = base64_decode(urldecode(input('u')));
        return $this->redirect($url);
    }
}
